<template>
  <div class="share-box">
    <el-popover
      @show="popShow"
      ref="popover1"
      placement="left"
      width="200"
      trigger="hover"
    >
      <div class="pop-box">
        <span>请使用微信扫码后分享</span>
      </div>
      <div id="qrcode" class="qr-code" ref="qrCodeDiv"></div>
    </el-popover>

    <div class="item-box">
      <div @click="handBtn('wb', $event)" class="item pointer">
        <img class="itme-img" src="@/assets/imgs/weibo.png" alt />
      </div>
      <!-- @click="handBtn('wx')" -->
      <div v-popover:popover1 class="item pointer">
        <img class="itme-img" src="@/assets/imgs/weixin.png" alt />
      </div>
      <div v-if="scShow" class="item-box">
        <div class="item pointer">
          <img
            @click="handBtn('sc')"
            v-if="favoritesId == null"
            class="itme-img"
            src="@/assets/imgs/shoucang.png"
            alt
          />
          <img
            @click="handBtn('sc')"
            v-else
            class="itme-img"
            src="@/assets/imgs/shoucang-active.png"
            alt
          />
        </div>

        <!-- <div
          :style="{
            color: favoritesId == null ? '#D8D8D8' : '#0050A5',
            textAlign: 'center',
          }"
          @click="handBtn('sc')"
          class="item pointer el-icon-star-on itme-img"
        ></div> -->
      </div>
      <div v-if="isPrint" v-print="'#printTest'" class="item pointer">
        <img class="itme-img" src="@/assets/imgs/dayin.png" alt />
        <!-- dayin.png -->
        <!-- <div
          :style="{
            color: '#D8D8D8',
            textAlign: 'center',
          }"
          class="item pointer el-icon-printer itme-img"
        ></div> -->
      </div>
    </div>

    <div @click="handBtn('ht')" class="share-btn pointer">
      <img src="@/assets/imgs/zhiding.png" alt="" />
    </div>
  </div>
</template>
<script>
import QRCode from "qrcodejs2";
export default {
  props: {
    scShow: {
      type: Boolean,
      default: false,
    },
    isPrint: {
      type: Boolean,
      default: false,
    },
    favoritesId: {
      default: null,
    },
  },
  data() {
    return {
      routes: [],
      activeRoute: "/",
      wxLoc: "",
    };
  },
  created() {},
  watch: {
    $route: function (val) {
      this.activeRoute = val.path;
    },
  },
  methods: {
    popShow() {
      document.getElementById("qrcode").innerHTML = "";
      this.wxLoc = document.location.href;
      new QRCode(this.$refs.qrCodeDiv, {
        text: document.location.href,
        width: 130,
        height: 130,
        colorDark: "#333333", //二维码颜色
        colorLight: "#ffffff", //二维码背景色
        correctLevel: QRCode.CorrectLevel.L, //容错率，L/M/H
      });
      console.log(this.wxLoc);
    },
    handBtn(nav) {
      this.$emit("handBtn", nav);
      if (nav == "ht") {
        var timer = setInterval(function () {
          let osTop =
            document.documentElement.scrollTop || document.body.scrollTop;
          let ispeed = Math.floor(-osTop / 5);
          document.documentElement.scrollTop = document.body.scrollTop =
            osTop + ispeed;
          // this.isTop = true
          if (osTop === 0) {
            clearInterval(timer);
          }
        }, 30);
      }
      if (nav == "wb") {
        var _title,
          _source,
          _sourceUrl,
          _pic,
          _showcount,
          _desc,
          _summary,
          _site,
          _width = 600,
          _height = 600,
          _top = (screen.height - _height) / 2,
          _left = (screen.width - _width) / 2,
          _pic = "";
        var _shareUrl =
          "http://v.t.sina.com.cn/share/share.php?&appkey=895033136"; //真实的appkey，必选参数
        let loc = document.location;
        _shareUrl += "&url=" + encodeURIComponent(loc); //参数url设置分享的内容链接|默认当前页location，可选参数
        _shareUrl += "&title=" + encodeURIComponent(_title || document.title); //参数title设置分享的标题|默认当前页标题，可选参数
        _shareUrl += "&source=" + encodeURIComponent(_source || "");
        _shareUrl += "&sourceUrl=" + encodeURIComponent(_sourceUrl || "");
        _shareUrl += "&content=" + "utf-8"; //参数content设置页面编码gb2312|utf-8，可选参数
        _shareUrl += "&pic=" + encodeURIComponent(_pic || ""); //参数pic设置图片链接|默认为空，可选参数
        window.open(
          _shareUrl,
          "_blank",
          "width=" +
            _width +
            ",height=" +
            _height +
            ",top=" +
            _top +
            ",left=" +
            _left +
            ",toolbar=no,menubar=no,scrollbars=no, resizable=1,location=no,status=0"
        );
      }
    },
  },
};
</script>
<style lang="less" scoped>
@import "~@/assets/less/flex.less";
@import "~@/assets/less/reset.less";
.qr-code {
  width: 130px;
  height: 130px;
  margin: 20px auto;
}
.share-btn {
  width: 50px;
  height: 50px;
  img {
    width: 50px;
    height: 50px;
  }
}
.pop-box {
  text-align: center;
  display: flex;
  flex-direction: column;
  justify-content: center;
  text-align: center;
  width: 100%;
  padding: 0 16px;
  padding-top: 10px;
}
.share-box {
  position: fixed;
  bottom: 40px;
  right: 30px;
  z-index: 999999999999;
  .share-btn {
    width: 50px;
    height: 50px;
    background-color: #e0e0e0;
    line-height: 50px;
    color: #999999;
    border-radius: 6px;
    text-align: center;
    &:hover {
      color: #fff;
    }
  }
  .item-box {
    .item {
      font-size: 32px;
      width: 50px;
      height: 50px;
      border: 1px solid #ededed;
      border-radius: 4px;
      background-color: #fff;
      margin-bottom: 10px;
      line-height: 50px;
      position: relative;
      &:hover {
        background-color: #f0f0f0;
      }
      .itme-img {
        width: 28px;
        height: 25px;
        min-width: 28px;
        min-height: 25px;
        position: absolute;
        top: 50%;
        left: 50%;
        transform: translate(-50%, -50%);
      }
    }
  }
}
</style>
